package algotithm.leetcode.math.面试题1704;

/**
 * @author zhouyanxiang
 * @Date 2021-03-2021/3/2-10:05
 * @URL https://leetcode-cn.com/problems/missing-number-lcci/
 * @Title 面试题 17.04. 消失的数字
 */
public class Solution {

    public static void main(String[] args) {
        int[] nums = {0,1,3};
        Solution solution = new Solution();
        int number = solution.missingNumber(nums);
        System.out.println(number);
    }

    public int missingNumber(int[] nums) {
        int n = nums.length;
        int sum = n * (n + 1) / 2;
        for (int num : nums) {
            sum -= num;
        }
        return sum;
    }

}
